<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>分享</title>
    <link rel="stylesheet" type="text/css" href="../css/api.css" />
    <style>
        body,html {background: rgba(0, 0, 0, 0);}
        header {width: 100%;height: 100vh;}
        .fxTitle{font-size: 16px;color: #d81e06;text-align: center;}
        .fx_msg{color: #000;font-size: 12px;text-align: center;margin:0 0px 10px;padding: 0px 0px;}
        footer {box-sizing: border-box;width: 100%;padding: 0 0;position: fixed;width: 100%;}
        footer div {padding: 15px;background: #fff;border-radius:15px 15px 0 0;}
        footer span {font-size: 14px;font-weight: bolder;width: 100%;text-align: center;margin-bottom: 10px;}
        footer ul {display: flex;justify-content: space-around;align-items: center;}
        footer ul li{width: 25%;}
        footer li span{font-size:12px !important;font-weight: normal;color: #000;}
        footer li img {width: 60%;margin: 5px 20%;}
    </style>
</head>

<body>
    <header onclick="back()" tapmode=""></header>
    <footer>
        <div>
            <span class="fxTitle"></span>
            <p class="fx_msg"></p>
            <ul>
                <li onclick="wxFx(1)">
                    <img src="../image/share_icon_wechat.png" alt="">
                    <span>微信好友</span>
                </li>
                <li onclick="wxFx(1)">
                    <img src="../image/share_icon_weixinqun.png" alt="">
                    <span>微信群</span>
                </li>
                <li onclick="wxFx(0)">
                    <img src="../image/share_icon_circleoffriends.png" alt="">
                    <span>朋友圈</span>
                </li>
                <!-- <li onclick="wxFx()">
                    <img src="../image/share_icon_haibao.png" alt="">
                    <span>分享海报</span>
                </li> -->
            </ul>
        </div>
    </footer>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript">
    let wx, sharedModule, item, detail, pages, data;
    apiready = function () {
        $api.dom('footer').style.bottom = api.safeArea.bottom + 'px';
        if(api.pageParam.type == 2){ //淘礼金商品
            document.getElementsByClassName("fxTitle")[0].innerHTML = '分享好友'
            document.getElementsByClassName("fx_msg")[0].innerText = ''
        }else{
            document.getElementsByClassName("fxTitle")[0].innerHTML =  '赚' + '<em style="font-size:24px;">'+api.pageParam.numberMoney+'</em>'
            document.getElementsByClassName("fx_msg")[0].innerText =  '分享后好友购买预估可赚￥' +api.pageParam.numberMoney+'元'
        }
        wx = api.require('wx');
        sharedModule = api.require('shareAction');
        item = api.pageParam.item;
        detail = api.pageParam.detail.length > 0 ? api.pageParam.detail : [];
        detail.push(item.pict_url);
        pages = api.pageParam.pages;
        setTimeout(() => {
            api.setFrameAttr({
                name: 'item_fx',
                bgColor: "rgba(0,0,0,0.1)",
            });
        }, 300);
    }

    function back() {
        api.setFrameAttr({
            name: 'item_fx',
            bgColor: "rgba(0,0,0,0)",
        });
        api.closeFrame({
        });
    }

    function wxFx(type) {
        data = 'item_id=' + item.item_id + '&images=' + detail + '&end_price_one=' + (String(item.end_price).split(".")[0]) +
            '&end_price_two=' + (String(item.end_price).split(".")[1] ? "." + String(item.end_price).split(".")[1].slice(0, 2) : "") +
            '&zk_final_price=' + item.zk_final_price + '&volume=' + item.volume + '&user_type=' + item.user_type +
            '&title=' + item.title + '&coupon_amount=' + (item.coupon_amount ? item.coupon_amount : 0.00) +
            '&coupon_start_time=' + item.coupon_start_time + '&coupon_end_time=' + item.coupon_end_time +
            '&coupon_start_time=' + item.coupon_start_time + '&pict_url=' + api.pageParam.shopAvatarImg +
            '&shop_title=' + item.shop_title + '&profit=' + item.per_price +
            '&save=' + item.save_money;
          $api.ajax({
              url: 'api/Member/share_url',
              method: 'get',
          }, function (ret) {
              if(type == 1 || type == 0){  //微信分享
                console.log(ret.data.share_url + 'api/oauth/item?item=' + encodeURIComponent(data) + '&sign=' +
                    api.getGlobalData({key: 'member_info'}).sign)
                wx.shareWebpage({
                    apiKey: '',
                    scene: type ? 'session' : 'timeline',
                    title: item.title,
                    description: '¥' + item.end_price,
                    thumb: '../image/sheng.png',
                    contentUrl: ret.data.share_url + 'api/oauth/item?item=' + encodeURIComponent(data) + '&sign=' +
                        api.getGlobalData({key: 'member_info'}).sign,
                }, function (ret, err) {
                    if (ret.status) {
                        api.toast({
                            msg: '分享成功',
                            duration: 3000,
                            location: 'middle'
                        });
                    } else {
                        api.toast({
                            msg: '分享失败',
                            duration: 3000,
                            location: 'middle'
                        });
                    }
                });
              }else if(type == '' || type == undefined){
                    var ercodeurl=ret.data.share_url+'api/oauth/item?item='+encodeURIComponent(data)+
                      '&sign='+api.getGlobalData({key: 'member_info'}).sign;
                    console.log(ercodeurl)
                    api.toast({
                        msg: '海报制作',
                        duration: 3000,
                        location: 'middle'
                    });
              }
          })
    }
    function share() {
        sharedModule.share({
            text: '点击查看商品：' + api.getGlobalData({
                key: 'config_info'
            }).share_url +
                'api/oauth/item?item=' +
                encodeURIComponent(data) +
                '&sign=' +
                api.getGlobalData({
                    key: 'member_info'
                }).sign,
            type: 'text'
        });
    }
</script>

</html>
